package server.main.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.util.AntPathMatcher;
import server.main.mapper.AccountMapper;
import server.main.mapper.FunctionPageMapper;
import server.main.mapper.PermissionMapper;
import server.main.mapper.RoleMapper;
import server.main.pojo.Account;
import server.main.pojo.FunctionPage;
import server.main.pojo.Role;
import server.main.service.AccountService;
import server.main.service.AfterService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @auther MingHsZzz
 * @Date 2022/9/19  19:02
 * @project main
 * @description
 */

@Service("AfterService")
public class AfterServiceImpl implements AfterService {

   @Autowired
   PermissionMapper permissionMapper;

   @Autowired
   AccountMapper accountMapper;

   @Autowired
   RoleMapper roleMapper;


   @Autowired
   FunctionPageMapper functionPageMapper;


   @Autowired
   AccountService accountService;
   /**
    * 获取前端菜单
    * @param jobnum 工号
    * @return JsonString
    */
   @Override
   public Map<String,List<String>> getMenu(String jobnum) {
      List<FunctionPage> goal = new ArrayList<>();


      Map<String,List<String>> map = new HashMap<>();

      //获取到该用户的所有的权限
      List<FunctionPage> userMenu = accountService.getFunctionPages(jobnum);

      for (FunctionPage menu : userMenu) {
         if(!map.containsKey(menu.getTitle())){
            map.put(menu.getTitle(),new ArrayList<String>());
            map.get(menu.getTitle()).add(menu.getUrl());

         }else {
            if(map.get(menu.getTitle()).contains(menu.getUrl())){
               continue;
            }
            map.get(menu.getTitle()).add(menu.getUrl());
         }
      }


      return map;

   }
}
